<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE html>
<html>
<head>
<title>39 | 添加节点</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta charset="UTF-8">
<meta name="keywords"
	content="Modern Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript">
	
	 addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } 

</script>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel='stylesheet' />
<!-- Custom CSS -->
<link href="css/style.css" rel='stylesheet' />
<!-- jQuery -->
<script src="js/jquery.min.js"></script>
<!-- Metis Menu Plugin JavaScript -->
<script src="js/metisMenu.min.js"></script>
<script src="js/custom.js"></script>
<style type="text/css">
.myspan {
	color: red;
}
</style>
<script>
	$(document).ready(
			function() {
				$("#node_describe").blur(
						function() {
							if ($("#node_describe").val() == null
									|| $("#node_describe").val() == "") {
								$("#span_describe").text("请填写节点描述");

							} else {
								$("#span_describe").text("√");
							}
						});
			});

	window.onload = function() {
		var firstplan_project = document.getElementById("firstplan_project");
		firstplan_project.innerHTML = window.opener.firstplan_project_name.value;
		var firstplan_id = document.getElementById("firstplan_id");
		firstplan_id.value = window.opener.firstplan_id.value;
		var nowDate = new Date();
		var node_settime = document.getElementById("node_settime");
		node_settime.value = nowDate.getFullYear() + "-"
				+ (nowDate.getMonth() + 1) + "-" + nowDate.getDate() + " "
				+ nowDate.getHours() + ":" + nowDate.getMinutes() + ":"
				+ nowDate.getSeconds();
	};

	function fun() {
		if (validated()) {
			document.getElementById("addform").submit();
		}
	}

	function validated() {
		if ($("#node_describe").val() == null
				|| $("#node_describe").val() == "") {
			$("#span_describe").text("请填写节点描述");
			return false;
		} else {
			$("#span_describe").text("√");
		}

		return true;
	}

	function getWorkDate() {
		var starttime = document.getElementById("starttime");
		var endtime = document.getElementById("endtime");
		var startDate = starttime.value;
		var endDate = endtime.value;
		var sArr = startDate.split("-");
		var eArr = endDate.split("-");
		var sDate = new Date(sArr[0], sArr[1], sArr[2]);
		var eDate = new Date(eArr[0], eArr[1], eArr[2]);
		var result = (eDate - sDate) / (24 * 60 * 60 * 1000);

		var workdate = document.getElementById("workdate");
		var node_workdays = document.getElementById("node_workdays");
		if (isNaN(result)) {
			workdate.innerHTML = 0;
			node_workdays.value = 0;
			return;
		}

		workdate.innerHTML = result;
		node_workdays.value = result;
	}

	function display() {
		var workday = document.getElementsByClassName("workday");
		var not_sure = document.getElementById("not_sure");
		if (not_sure.checked) {
			for ( var i = 0; i < workday.length; i++) {
				workday[i].style.display = "none";
			}
			var starttime = document.getElementById("starttime");
			var endtime = document.getElementById("endtime");
			var workdate = document.getElementById("workdate");
			var node_workdays = document.getElementById("node_workdays");
			starttime.value = null;
			endtime.value = null;
			workdate.innerHTML = 0;
			node_workdays.value = 0;

		} else {
			for ( var i = 0; i < workday.length; i++) {
				workday[i].style.display = "";
			}
		}
	}
</script>
</head>
<body>
	<div id="wrapper">
		<!-- Navigation -->
		<div id="page-wrapper">
			<div class="xs">
				<div class="well1 white">
					<h3 align="center">
						请为<span id="firstplan_project" style="color:red;"></span>的一级计划添加节点
					</h3>
					<form id="addform" method="post" action="addNode">

						<table class="table">
							<tr>
								<th>上级相关节点</th>
								<td><c:choose>
										<c:when test="${fn:length(nodeList) == 0 }">
											暂无上级相关节点
										</c:when>
										<c:otherwise>
											<select name="node.relatedNode.id">
												<c:forEach items="${nodeList }" var="n">
													<option value="${n.id }">${n.node_result}</option>
												</c:forEach>
											</select>
										</c:otherwise>
									</c:choose></td>
							</tr>
							<tr>
								<th>节点生产来源</th>
								<td>
									<!-- 以前为手动填写，更改为下拉列表选取 --> <select name="node.nodeFileSource">
										<c:forEach items="${fileList}" var="file">
											<option value="${file }">${file }</option>
										</c:forEach>
								</select></td>
								<th>节点专业类型</th>
								<td>
									<!-- 以前为手动填写，更改为下拉列表选取 --> <select name="node.nodeType.id">
										<c:forEach items="${nodeTypeList}" var="ns">
											<option value="${ns.id }">${ns.node_type }</option>
										</c:forEach>
								</select></td>
							</tr>
							<tr>
								<th>节点所属生命周期</th>
								<td><select name="node.lc.id">
										<c:forEach items="${lifeCycleList }" var="lc">
											<option value="${lc.id }">${lc.name_lifecycle }</option>
										</c:forEach>
								</select></td>
								<th>节点关键度</th>
								<td><select name="node.node_level">
										<option value="1">一级</option>
										<option value="2">二级</option>
										<option value="3">三级</option>
								</select></td>
							</tr>
							<tr>
								<th>是否考核节点</th>
								<td><input type="radio" name="node.node_exam" value="1"
									id="kaohe0"><label for="kaohe0">是</label> <input
									type="radio" name="node.node_exam" value="0" checked="checked"
									id="kaohe1"><label for="kaohe1">否</label></td>
								<th>是否里程碑节点</th>
								<td><input type="radio" name="node.node_milestone"
									value="1" id="lichengbei0"><label for="lichengbei0">是</label>
									<input type="radio" name="node.node_milestone" value="0"
									checked="checked" id="lichengbei1"><label
									for="lichengbei1">否</label></td>
							</tr>
							<div id="workday">
								<tr class="workday">
									<th>节点要求开始时间</th>
									<td><input type="date" id="starttime"
										onblur="getWorkDate();" name="node.node_starttime" /> <span
										id="span_start" class="myspan"></span></td>
								</tr>
								<tr class="workday">
									<th>节点要求结束时间</th>
									<td><input type="date" id="endtime"
										onblur="getWorkDate();" name="node.node_endtime" /> <span
										id="span_end" class="myspan"></span></td>
								</tr>

								<tr>
									<th class="workday">节点需要的工日</th>
									<td class="workday"><span id="workdate">0</span>天 <input
										type="hidden" name="node.node_workdays" id="node_workdays"
										value="" /></td>
							</div>

							<th colspan="2"><input type="checkbox" id="not_sure"
								onclick="display();" /><label for="not_sure">暂不确定开始/结束时间</label>
							</th>
							</tr>

							<tr>
								<th>节点成果形式</th>
								<td><input id="node_result" type="text"
									name="node.node_result"> <span id="span_result"
									class="myspan"></span></td>

								<th>节点责任部门</th>
								<td><select name="node.department.id">
										<c:forEach items="${deptList }" var="dept" begin="0" end="8">
											<option value="${dept.id }">${dept.dept_name }</option>
										</c:forEach>
								</select> <span id="span_dept" class="myspan"></span></td>
							</tr>

							<tr>
								<th>节点描述</th>
								<td colspan="3"><textarea id="node_describe"
										name="node.node_describe" cols="80" rows="2"></textarea> <span
									id="span_describe" class="myspan"></span></td>
							</tr>

							<%-- <tr>
								<th>节点工作内容</th>
								<td colspan="3">
									<textarea id="node_workdetails" name="node.node_workdetails"  cols="80" rows="4"></textarea>
									<span id="span_details" class="myspan"></span>
								</td>
							</tr> --%>

							<tr>
								<th>节点备注</th>
								<td colspan="3"><textarea name="node.node_remark" cols="80"
										rows="2"></textarea> <span id="span_remark" class="myspan"></span>
								</td>
							</tr>

						</table>

						<input type="hidden" value="" name="node.firstplan.id"
							id="firstplan_id" /> <input type="hidden" value=""
							name="node_settime" id="node_settime" />

						<div class="form-group" align="center">
							<input type="button" id="add_node_button" class="btn btn-primary"
								onclick="fun()" value="添加节点" /> <span id="add_node_span"
								class="myspan"></span> <input type="button"
								class="btn btn-primary" onclick="window.close();" value="关闭" />
						</div>
					</form>
				</div>
			</div>
		</div>
		<!-- /#page-wrapper -->
	</div>
	<!-- /#wrapper -->
</body>
</html>
